﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using WebService.DAO;
using WebService.VO;

namespace WebService.BUS
{
    public class UserPlacesBUS
    {
        UserPlacesDAO placesDAO;
        /// <summary>
        /// khởi tạo đối tượng xử lý dl
        /// </summary>
        public UserPlacesBUS()
        {
            placesDAO = new UserPlacesDAO();
        }

         /// <summary>
         /// get user place by device id
         /// </summary>
         /// <param name="device"></param>
         /// <returns></returns>
         public DataTable getUserPlaces(DeviceVO device, string language)
         {
             DataTable dt = placesDAO.getUserPlaces(device, language);
             foreach (DataRow row in dt.Rows)
             {
                 for (int i = 0; i < dt.Columns.Count; i++)
                 {


                     dt.Columns[i].ReadOnly = false;

                     if (string.IsNullOrEmpty(row[i].ToString()))
                     {
                         if (dt.Columns[i].DataType == typeof(string))
                             row[i] = "NULL";
                         else if (dt.Columns[i].DataType == typeof(int))
                             row[i] = new int();
                         else if (dt.Columns[i].DataType == typeof(DateTime))
                             row[i] = new DateTime();
                     }
                 }
             }
             return dt;
         }

         /// <summary>
         /// check item existing in user places
         /// </summary>
         /// <param name="favorite"></param>
         /// <returns></returns>
         public bool check(UserPlaceVO place)
         {
             return placesDAO.check(place);
         }

         /// <summary>
         /// add item to user places
         /// </summary>
         public void insert(UserPlaceVO place)
         {
             placesDAO.insert(place);
         }

         /// <summary>
         /// delete item from user places
         /// </summary>
         public void delete(UserPlaceVO place)
         {
             placesDAO.delete(place);
         }
    }
}